package org.example.springboot;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/messages")
public class MessageController {

    List<MessageInfo> list = new ArrayList<>();
    @RequestMapping("/publish")
    public boolean publish(MessageInfo messageInfo) {
        // 校验三个变量是否为空
        if (!StringUtils.hasLength(messageInfo.getFrom())
                || !StringUtils.hasLength(messageInfo.getTo())
                || !StringUtils.hasLength(messageInfo.getMessage())) {
            return false;
        }

        // 不为空，将内容存入List
        list.add(messageInfo);
        return true;
    }

    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        for (MessageInfo messageInfo : list) {

        }
        // 获取所有留言信息
        return list;
    }
}
